<template>
  <div class="first-container">
    <p class="warn-text">若不授权个人信息，则无法使用本小程序提供的相关功能。本小程序保证不收集、公开、使用您的隐私信息，请您授权后使用。</p>
    <button class="userButton" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">使用微信授权登录</button>

  </div>
</template>

<script>
// import { userLogin, getUserInfo } from '@/api/index';
export default {
  data () {
    return {}
  },
  methods: {
    bindGetUserInfo (e) {
      console.log('yonghuxinxi', e.mp.detail.userInfo)
      this.wxLogin()
      console.log('yonghuxinxi')
    },
    wxLogin () {
      // let code
      // let result
      // let that = this
      wx.login({
        success: ret => {
          // let _this = this
          if (ret.code) {
            // code = ret.code
            wx.getUserInfo({
              success: res => {
                console.log('成功了', res)
                wx.setStorageSync('userInfo', res.userInfo)
                wx.switchTab({
                  url: '../index/main'
                })
                // result = res.userInfo
                // result.iv = res.iv
                // result.encryptedData = res.encryptedData
                // let str = JSON.stringify(result)
                // userLogin(code, str).then(res => {
                //   wx.setStorageSync('token', res.data.token)
                //   wx.switchTab({
                //     url: '../index/main'
                //   })
                // })
              },
              fail: ret => {
                console.log('失败了', ret)
              }
            })
          }
        }
      })
    }
  },
  onShareAppMessage () {
    return {
      imageUrl: 'http://p0zxz4uq2.bkt.clouddn.com/sharepic01.jpg'
    }
  }
}
</script>

<style>
page {
  height: auto;
  width: 100%;
  background: #fff;
}
.userButton {
  margin: 100px 30px;
  background-color: #22ac38;
  color: #fff;
  font-size: 34rpx;
}
.warn-text {
  font-size: 28rpx;
  color: #bbb;
  margin: 100px 30px;
  text-indent: 2em;
  line-height: 56rpx;
}
</style>
